*------------------------------------------------------------------------------
* PROGRAM: regressions for Uganda Trees & Trust papers
* CODER : Sarah Walker
* DATE: 2/25/25
*------------------------------------------------------------------------------


// set directory -- add your own for fun!!!

if "`c(username)'" == "XXX" {
	global path "XXX"
}

global treetablesuganda "$path/Outputs/Trees Experiment/Tables"
global treefiguresuganda "$path/Outputs/Trees Experiment/Figures"

use "$path/Data/Uganda_WTA_Trees_clean_anon.dta", replace 

set scheme s2color

*--------------------------------------------------------------------------*
* Reshape Long
*--------------------------------------------------------------------------*
 
reshape long share_cut_r trees_cut_r, i(HHID) j(round)
egen distid = group(DISTRICT)
egen hhid = group(HHID)

*--------------------------------------------------------------------------*
* Calculate Total Rounds Played *
*--------------------------------------------------------------------------*
g stop = round if trees_cut==.
bysort HHID: egen round_stop = min(stop)

replace round_stop = round_stop-1
replace round_stop = 10 if round_stop==.

* Summarize rounds played by treatment group *
preserve 
duplicates drop HHID, force

bysort trees_treat: sum round_stop

restore


*--------------------------------------------------------------------------*
*--------------------------------------------------------------------------*
* Main results that drop missing observations
*--------------------------------------------------------------------------*
*--------------------------------------------------------------------------*

* Share cut by treatment group *
*--------------------------------------------------------------------------*
local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3"
local controls_additional "consumption female C9 risk D6_9 acresland cutstreescharc"

label var trees_insecure "Insecure" 
label var trees_certificate "Certificate"

estimates clear

* No controls *
eststo: reghdfe share_cut trees_insecure trees_certificate, abs(round) vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'


* Add unbalanced controls *
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced', abs(round) vce(robust) 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' , abs(round)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional', abs(round enumid)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional', abs(round vname)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

esttab using "$treetablesuganda/trees_main_drop_missing.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" "s3 P-value Insecure=Certificate") keep(trees_insecure trees_certificate) prehead(\begin{tabular}{l*{5}{c}} \hline \hline DV: Share trees cut each round  & (1) & (2) & (3) & (4) & (5)\\) posthead(\hline \\) prefoot(\\ Unbalanced controls: & N & Y & Y & Y & Y \\ Additional controls: & N & N & Y & Y & Y \\ Enumerator FE: & N & N & N & Y & N \\ Village FE: & N & N & N & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. Unbalanced controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, patience, mailo land tenure, private land tenure. Additional controls include: asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Robust standard errors in parentheses.} \end{tablenotes} )
estimates clear


* Share cut interacted with village mailo *
*--------------------------------------------------------------------------*
local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience E8_3"

bysort vname: egen vmailo = mean(mailo)

g insecuremailo = trees_insecure*vmailo
g certificatemailo = trees_certificate*vmailo
egen vname_round = group(vname round)

label variable insecuremailo 	"Insecure X \% Mailo Village" 
label variable certificatemailo "Certificate X \% Mailo Village" 
label var vmailo "\% Mailo Village"

* No controls *
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo, abs(round)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

* Add unbalanced controls *
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo `controls_ug_unbalanced', abs(round)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

* Add controls from the PAP * 
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo `controls_ug_unbalanced' `controls_additional', abs(round) vce(robust)  
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo `controls_ug_unbalanced' `controls_additional', abs(round enumid)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo `controls_ug_unbalanced' `controls_additional', abs(round DISTRICT)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

esttab using "$treetablesuganda/trees_interaction_village_drop_missing.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes noomit style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" ) keep(trees_insecure insecuremailo trees_certificate certificatemailo vmailo) prehead(\begin{tabular}{l*{5}{c}} \hline \hline DV: Share trees cut each round  & (1) & (2) & (3) & (4) & (5)\\) posthead(\hline \\) prefoot(\\ Unbalanced controls: & N & Y & Y & Y & Y \\ Additional controls: & N & N & Y & Y & Y \\ Enumerator FE: & N & N & N & Y & N \\ District FE: & N & N & N & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. Unbalanced controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, and patience. Additional controls include: asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Robust standard errors in parentheses.} \end{tablenotes} )
estimates clear


*--------------------------------------------------------------------------*
*--------------------------------------------------------------------------*
* Replacing missing controls with median and controlling for missings
*--------------------------------------------------------------------------*
*--------------------------------------------------------------------------*

use "$path/Data/Uganda_WTA_Trees_clean.dta", replace 

foreach v in C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3 consumption female C9 risk D6_9 acresland cutstreescharc {
	
	g miss_`v' = `v'==.
	sum `v', d
	replace `v' = r(p50) if `v'==.
	
}

reshape long share_cut_r trees_cut_r, i(HHID) j(round)
egen distid = group(DISTRICT)
egen hhid = group(HHID)

*--------------------------------------------------------------------------*
* Trees Regressions - Baseline - ITT
*--------------------------------------------------------------------------*

local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3"
local controls_additional "consumption female C9 risk D6_9 acresland cutstreescharc"

label var trees_insecure "Insecure" 
label var trees_certificate "Certificate"

estimates clear

* No controls *
eststo: reghdfe share_cut trees_insecure trees_certificate, abs(round miss*) 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'


* Add unbalanced controls *
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced', abs(round miss*)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' , abs(round miss*)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional', abs(round miss* enumid)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional', abs(round miss* vname) vce(robust) 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

esttab using "$treetablesuganda/trees_main.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" "s3 P-value Insecure=Certificate") keep(trees_insecure trees_certificate) prehead(\begin{tabular}{l*{5}{c}} \hline \hline DV: Share trees cut each round  & (1) & (2) & (3) & (4) & (5)\\) posthead(\hline \\) prefoot(\\ Unbalanced controls: & N & Y & Y & Y & Y \\ Additional controls: & N & N & Y & Y & Y \\ Enumerator FE: & N & N & N & Y & N \\ Village FE: & N & N & N & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. Unbalanced controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, patience, mailo land tenure, private land tenure. Additional controls include: asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Robust standard errors in parentheses. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear


*--------------------------------------------------------------------------*
* Main effect by trust level - JAG (SW update August 2024)
*--------------------------------------------------------------------------*

local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3"
local controls_additional "consumption female C9 risk D6_9 acresland cutstreescharc"

label var trees_insecure "Insecure" 
label var trees_certificate "Certificate"

estimates clear

* LOW TRUST 
*--------------------------------------------------------
* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' if trust_sent <=2000, abs(round miss* enumid)  vce(robust)
sum share_cut if trees_secure==1 & trust_sent <=2000
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' if trust_sent <=2000, abs(round miss* vname)  vce(robust)
sum share_cut if trees_secure==1 & trust_sent <=2000
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'


* HIGH TRUST 
*--------------------------------------------------------
* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' if trust_sent > 2000, abs(round miss* enumid)  vce(robust)
sum share_cut if trees_secure==1 & trust_sent <=2000
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' if trust_sent > 2000, abs(round miss* vname) vce(robust) 
sum share_cut if trees_secure==1 & trust_sent > 2000
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

esttab using "$treetablesuganda/trees_main_trust.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" "s3 P-value Insecure=Certificate") keep(trees_insecure trees_certificate) prehead(\begin{tabular}{l*{5}{c}} \hline \hline & \multicolumn{2}{c}{Low Trust} & \multicolumn{2}{c}{High Trust} \\ DV: Share trees cut each round  & (1) & (2) & (3) & (4) \\) posthead(\hline \\) prefoot(\\ Controls: & Y & Y & Y & Y \\ Enumerator FE: & Y & N & Y & N \\ Village FE: & N & Y & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. A participant is low trust if they sent less than (or equal to) half of the endowment in the trust game. A participant is high trust if they sent more than half of the endowment in the trust game. Controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, patience, mailo land tenure, private land tenure, asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Robust standard errors in parentheses. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear



*--------------------------------------------------------------------------*
* Trees Regressions - Baseline - ToT
*--------------------------------------------------------------------------*

local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3"
local controls_additional "consumption female C9 risk D6_9 acresland cutstreescharc"

label var trees_insecure "Insecure" 
label var certbuy "Bought certificate"
replace certbuy=0 if certbuy==.

estimates clear

* No controls *
eststo: ivreghdfe share_cut trees_insecure (certbuy=trees_certificate), abs(round miss*) robust
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=certbuy
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'


* Add unbalanced controls *
eststo: ivreghdfe share_cut trees_insecure (certbuy=trees_certificate) `controls_ug_unbalanced', abs(round miss*) robust
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=certbuy
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP * 
eststo: ivreghdfe share_cut trees_insecure (certbuy=trees_certificate) `controls_ug_unbalanced' `controls_additional' , abs(round miss*) robust 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=certbuy
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + enumerator fixed effects * 
eststo: ivreghdfe share_cut trees_insecure (certbuy=trees_certificate) `controls_ug_unbalanced' `controls_additional', abs(round miss* enumid) robust
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=certbuy
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + village fixed effects * 
eststo: ivreghdfe share_cut trees_insecure (certbuy=trees_certificate) `controls_ug_unbalanced' `controls_additional', abs(round miss* vname) robust 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=certbuy
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

esttab using "$treetablesuganda/trees_tot.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" "s3 P-value Insecure=Certificate") keep(trees_insecure certbuy) order(trees_insecure certbuy) prehead(\begin{tabular}{l*{5}{c}} \hline \hline DV: Share trees cut each round  & (1) & (2) & (3) & (4) & (5)\\) posthead(\hline \\) prefoot(\\ Unbalanced controls: & N & Y & Y & Y & Y \\ Additional controls: & N & N & Y & Y & Y \\ Enumerator FE: & N & N & N & Y & N \\ Village FE: & N & N & N & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. IV estimates, which instrument \textit{Bought certificate} with whether the respondent was in the certificate treatment group. Unit of observation is a person-round. All estimates control for round fixed effects. Unbalanced controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, patience, mailo land tenure, private land tenure. Additional controls include: asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Robust standard errors in parentheses. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear

*--------------------------------------------------------------------------*
* Trees Regressions - Baseline with HAC standard errors
*--------------------------------------------------------------------------*
tsset hhid round

local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3"
local controls_additional "consumption female C9 risk D6_9 acresland cutstreescharc"
local missing "miss_C8_1_TEXT miss_C1 miss_D6_2 miss_D6_7 miss_patience miss_mailo miss_private miss_E8_3 miss_consumption miss_female miss_C9 miss_risk miss_D6_9 miss_acresland miss_cutstreescharc"

label var trees_insecure "Insecure" 
label var trees_certificate "Certificate"

estimates clear

* No controls *
eststo: newey share_cut trees_insecure trees_certificate i.round `missing', lag(7) force
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'


* Add unbalanced controls *
eststo: newey share_cut trees_insecure trees_certificate i.round `missing' `controls_ug_unbalanced', lag(7) force
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP * 
eststo: newey share_cut trees_insecure trees_certificate i.round `missing' `controls_ug_unbalanced' `controls_additional' , lag(7) force 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + enumerator fixed effects * 
eststo: newey share_cut trees_insecure trees_certificate i.round `missing' i.enumid `controls_ug_unbalanced' `controls_additional', lag(7) force
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + village fixed effects * 
eststo: newey share_cut trees_insecure trees_certificate i.round `missing' i.vid `controls_ug_unbalanced' `controls_additional', lag(7) force 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

esttab using "$treetablesuganda/trees_main_hac.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" "s3 P-value Insecure=Certificate") keep(trees_insecure trees_certificate) prehead(\begin{tabular}{l*{5}{c}} \hline \hline DV: Share trees cut each round  & (1) & (2) & (3) & (4) & (5)\\) posthead(\hline \\) prefoot(\\ Unbalanced controls: & N & Y & Y & Y & Y \\ Additional controls: & N & N & Y & Y & Y \\ Enumerator FE: & N & N & N & Y & N \\ Village FE: & N & N & N & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. Unbalanced controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, patience, mailo land tenure, private land tenure. Additional controls include: asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Heteroskedasticity-autocorrelation consistent (HAC) standard errors in parentheses, estimated using the \textit{newey} command in Stata with 7 lags. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear


*--------------------------------------------------------------------------*
* Trees Regressions - Baseline with INDIVIDUAL CLUSTER standard errors
*--------------------------------------------------------------------------*
local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3"
local controls_additional "consumption female C9 risk D6_9 acresland cutstreescharc"

label var trees_insecure "Insecure" 
label var trees_certificate "Certificate"

estimates clear

* No controls *
eststo: reghdfe share_cut trees_insecure trees_certificate, abs(round miss*) cluster(HHID) 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'


* Add unbalanced controls *
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced', abs(round miss*) cluster(HHID)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' , abs(round miss*) cluster(HHID)  
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional', abs(round miss* enumid) cluster(HHID)  
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional', abs(round miss* vname) cluster(HHID)  
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

esttab using "$treetablesuganda/trees_main_cluster.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" "s3 P-value Insecure=Certificate") keep(trees_insecure trees_certificate) prehead(\begin{tabular}{l*{5}{c}} \hline \hline DV: Share trees cut each round  & (1) & (2) & (3) & (4) & (5)\\) posthead(\hline \\) prefoot(\\ Unbalanced controls: & N & Y & Y & Y & Y \\ Additional controls: & N & N & Y & Y & Y \\ Enumerator FE: & N & N & N & Y & N \\ Village FE: & N & N & N & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. Unbalanced controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, patience, mailo land tenure, private land tenure. Additional controls include: asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Standard errors clusterd at the participant level in parentheses. Missing observations for control variables replaced with the median value. All estimates control for missing observations. } \end{tablenotes} )
estimates clear


*--------------------------------------------------------------------------*
* ROBUSTNESS: Baseline, dropping people who deforest everything 
*--------------------------------------------------------------------------*
preserve

use "$path/Data/Uganda_WTA_Trees_clean.dta", replace 

* People who cut everything *
*--------------------------------------------------------------------------*
g cut_all=0

foreach v in HG12 HG15 HG18 HG111 HG114 HG117 HG120 HG123 HG126 HG129 HG22 HG26 HG210 HG214 HG218 HG222 HG226 HG230 HG234 HG238 HG32 HG34 HG36 HG38 HG310 HG312 HG314 HG316 HG318 HG320 {
	replace cut_all = 1 if `v'==0
}

* How different are they? - Normalized Differences *
*--------------------------------------------------------------------------*
estpost sum C8_1_TEXT female C1 C3 primaryschool secondaryschool C12_1_TEXT income_land acresland D1_1_TEXT E4_1_TEXT treecoverage cutstreescharc E8_1 E8_2 E8_3 B12a_1_TEXT consumption D6_1 D6_2  D6_3  D6_4  D6_5  D6_7  D7_7  risk patience trust mailo customary private trees_insecure trees_secure trees_certificate if cut_all==1
estimates store A

estpost sum C8_1_TEXT female C1 C3 primaryschool secondaryschool C12_1_TEXT income_land acresland D1_1_TEXT E4_1_TEXT treecoverage cutstreescharc E8_1 E8_2 E8_3 B12a_1_TEXT consumption D6_1 D6_2  D6_3  D6_4  D6_5  D6_7  D7_7  risk patience trust mailo customary private trees_insecure trees_secure trees_certificate if cut_all==0
estimates store B

foreach v in C8_1_TEXT female C1 C3 primaryschool secondaryschool C12_1_TEXT income_land acresland D1_1_TEXT E4_1_TEXT treecoverage cutstreescharc E8_1 E8_2 E8_3 B12a_1_TEXT consumption D6_1 D6_2  D6_3  D6_4  D6_5  D6_7  D7_7  risk patience trust mailo  customary private trees_insecure trees_secure trees_certificate {
	
	ttest `v' , by(cut_all)
	replace `v' = (r(mu_2) - r(mu_1))/(sqrt(r(sd_2)^2 + r(sd_1)^2))

}

estpost sum C8_1_TEXT female C1 C3 primaryschool secondaryschool C12_1_TEXT income_land acresland D1_1_TEXT E4_1_TEXT treecoverage cutstreescharc E8_1 E8_2 E8_3 B12a_1_TEXT consumption D6_1 D6_2  D6_3  D6_4  D6_5  D6_7  D7_7  risk patience trust mailo  customary private trees_insecure trees_secure trees_certificate
estimates store C

esttab A B C  using "$treetablesuganda/cutall_normdiff.tex", replace f cells("mean(fmt(3))") label collabels(none) mtitle( "Cut all trees" "Did not cut all trees" "Normalized difference") 


restore 



* Find the round in which they cut everything *
*--------------------------------------------------------------------------*
g cut_all=0

foreach v in HG12 HG15 HG18 HG111 HG114 HG117 HG120 HG123 HG126 HG129 HG22 HG26 HG210 HG214 HG218 HG222 HG226 HG230 HG234 HG238 HG32 HG34 HG36 HG38 HG310 HG312 HG314 HG316 HG318 HG320 {
	replace cut_all = 1 if `v'==0
}

g cutallround = 1 if HG12==0 | HG22==0 | HG32==0 
replace cutallround = 2 if HG15==0 | HG26==0 | HG34==0 
replace cutallround = 3 if HG18==0 | HG210==0 | HG36==0 
replace cutallround = 4 if HG111==0 | HG214==0 | HG38==0 
replace cutallround = 5 if HG114==0 | HG218==0 | HG310==0 
replace cutallround = 6 if HG117==0 | HG222==0 | HG312==0 
replace cutallround = 7 if HG120==0 | HG226==0 | HG314==0 
replace cutallround = 8 if HG123==0 | HG230==0 | HG316==0 
replace cutallround = 9 if HG126==0 | HG234==0 | HG318==0 
replace cutallround = 10 if HG129==0 | HG238==0 | HG320==0 

sum cutallround

* Regressions
*--------------------------------------------------------------------------*
* Define controls *
local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3"
local controls_additional "consumption female C9 risk D6_9 acresland cutstreescharc"

label var trees_insecure "Insecure" 
label var trees_certificate "Certificate"

estimates clear

* No controls *
eststo: reghdfe share_cut trees_insecure trees_certificate if cut_all==0, abs(round miss*) vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'


* Add unbalanced controls *
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' if cut_all==0, abs(round miss*) vce(robust) 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' if cut_all==0, abs(round miss*)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' if cut_all==0, abs(round miss* enumid) vce(robust) 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' if cut_all==0, abs(round miss* vname)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

esttab using "$treetablesuganda/trees_main_nocutall.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" "s3 P-value Insecure=Certificate") keep(trees_insecure trees_certificate) prehead(\begin{tabular}{l*{5}{c}} \hline \hline DV: Share trees cut each round  & (1) & (2) & (3) & (4) & (5)\\) posthead(\hline \\) prefoot(\\ Unbalanced controls: & N & Y & Y & Y & Y \\ Additional controls: & N & N & Y & Y & Y \\ Enumerator FE: & N & N & N & Y & N \\ Village FE: & N & N & N & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. Unbalanced controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, patience, mailo land tenure, private land tenure. Additional controls include: asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Robust standard errors in parentheses. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear




*--------------------------------------------------------------------------*
* Trees Regressions - interacted with mailo
*--------------------------------------------------------------------------*
local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience E8_3"

gen insecuremailo = trees_insecure*mailo
gen certificatemailo = trees_certificate*mailo

label variable insecuremailo 		"Insecure X Mailo" 
label variable certificatemailo 		"Certificate X Mailo" 


* No controls *
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo  mailo , abs(round miss*)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'



* Add unbalanced controls *
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo  mailo `controls_ug_unbalanced', abs(round miss*) vce(robust) 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'


* Add controls from the PAP * 
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo  mailo `controls_ug_unbalanced' `controls_additional', abs(round miss*)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo  mailo `controls_ug_unbalanced' `controls_additional', abs(round miss* enumid)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo  mailo `controls_ug_unbalanced' `controls_additional', abs(round miss* vname) vce(robust)
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

esttab using "$treetablesuganda/trees_interaction.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes noomit style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" ) keep(trees_insecure insecuremailo trees_certificate certificatemailo mailo) prehead(\begin{tabular}{l*{5}{c}} \hline \hline DV: Share trees cut each round  & (1) & (2) & (3) & (4) & (5)\\) posthead(\hline \\) prefoot(\\ Unbalanced controls: & N & Y & Y & Y & Y \\ Additional controls: & N & N & Y & Y & Y \\ Enumerator FE: & N & N & N & Y & N \\ Village FE: & N & N & N & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. Unbalanced controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, and patience. Additional controls include: asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Robust standard errors in parentheses. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear

*--------------------------------------------------------------------------*
* Trees Regressions - interacted with village level mailo
*--------------------------------------------------------------------------*
local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience E8_3"

bysort vname: egen vmailo = mean(mailo)

replace insecuremailo = trees_insecure*vmailo
replace certificatemailo = trees_certificate*vmailo
egen vname_round = group(vname round)

label variable insecuremailo 	"Insecure X \% Mailo Village" 
label variable certificatemailo "Certificate X \% Mailo Village" 
label var vmailo "\% Mailo Village"

* No controls *
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo, abs(round miss*)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'



* Add unbalanced controls *
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo `controls_ug_unbalanced', abs(round miss*) vce(robust) 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'


* Add controls from the PAP * 
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo `controls_ug_unbalanced' `controls_additional', abs(round miss*)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo `controls_ug_unbalanced' `controls_additional', abs(round miss* enumid)  vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo `controls_ug_unbalanced' `controls_additional', abs(round miss* DISTRICT) vce(robust) 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

esttab using "$treetablesuganda/trees_interaction_village.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes noomit style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" ) keep(trees_insecure insecuremailo trees_certificate certificatemailo vmailo) prehead(\begin{tabular}{l*{5}{c}} \hline \hline DV: Share trees cut each round  & (1) & (2) & (3) & (4) & (5)\\) posthead(\hline \\) prefoot(\\ Unbalanced controls: & N & Y & Y & Y & Y \\ Additional controls: & N & N & Y & Y & Y \\ Enumerator FE: & N & N & N & Y & N \\ District FE: & N & N & N & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. Unbalanced controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, and patience. Additional controls include: asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Robust standard errors in parentheses. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear



*--------------------------------------------------------------------------*
* Trees Regressions - interacted with village level mailo - HAC standard errors
*--------------------------------------------------------------------------*
tsset hhid round
local missing "miss_C8_1_TEXT miss_C1 miss_D6_2 miss_D6_7 miss_patience miss_mailo miss_E8_3 miss_consumption miss_female miss_C9 miss_risk miss_D6_9 miss_acresland miss_cutstreescharc"


* No controls *
eststo: newey share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo i.round `missing', lag(7) force 
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'


* Add unbalanced controls *
eststo: newey share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo i.round `controls_ug_unbalanced', lag(7) force  
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'


* Add controls from the PAP * 
eststo: newey share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo i.round `missing' `controls_ug_unbalanced' `controls_additional', lag(7) force  
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

* Add controls from the PAP + enumerator fixed effects * 
eststo: newey share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo i.round `missing' i.enumid `controls_ug_unbalanced' `controls_additional', lag(7) force  
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

* Add controls from the PAP + village fixed effects * 
eststo: newey share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo i.round `missing' i.distid `controls_ug_unbalanced' `controls_additional', lag(7) force  
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'


esttab using "$treetablesuganda/trees_interaction_village_hac.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes noomit style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" ) keep(trees_insecure insecuremailo trees_certificate certificatemailo vmailo) prehead(\begin{tabular}{l*{5}{c}} \hline \hline DV: Share trees cut each round  & (1) & (2) & (3) & (4) & (5)\\) posthead(\hline \\) prefoot(\\ Unbalanced controls: & N & Y & Y & Y & Y \\ Additional controls: & N & N & Y & Y & Y \\ Enumerator FE: & N & N & N & Y & N \\ District FE: & N & N & N & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. Unbalanced controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, and patience. Additional controls include: asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Heteroskedasticity-autocorrelation consistent (HAC) standard errors in parentheses, estimated using the \textit{newey} command in Stata with 7 lags. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear

*--------------------------------------------------------------------------*
* Trees Regressions - interacted with village level mailo - Cluster SEs at individual level
*--------------------------------------------------------------------------*
local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience E8_3"

*bysort vname: egen vmailo = mean(mailo)

replace insecuremailo = trees_insecure*vmailo
replace certificatemailo = trees_certificate*vmailo
*egen vname_round = group(vname round)

label variable insecuremailo 	"Insecure X \% Mailo Village" 
label variable certificatemailo "Certificate X \% Mailo Village" 
label var vmailo "\% Mailo Village"

* No controls *
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo, abs(round miss*) cluster(HHID)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'



* Add unbalanced controls *
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo `controls_ug_unbalanced', abs(round miss*) cluster(HHID)  
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'


* Add controls from the PAP * 
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo `controls_ug_unbalanced' `controls_additional', abs(round miss*) cluster(HHID)  
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo `controls_ug_unbalanced' `controls_additional', abs(round miss* enumid) cluster(HHID)  
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut trees_insecure insecuremailo trees_certificate certificatemailo vmailo `controls_ug_unbalanced' `controls_additional', abs(round miss* DISTRICT) cluster(HHID)  
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'

esttab using "$treetablesuganda/trees_interaction_village_cluster.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes noomit style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" ) keep(trees_insecure insecuremailo trees_certificate certificatemailo vmailo) prehead(\begin{tabular}{l*{5}{c}} \hline \hline DV: Share trees cut each round  & (1) & (2) & (3) & (4) & (5)\\) posthead(\hline \\) prefoot(\\ Unbalanced controls: & N & Y & Y & Y & Y \\ Additional controls: & N & N & Y & Y & Y \\ Enumerator FE: & N & N & N & Y & N \\ District FE: & N & N & N & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. Unbalanced controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, and patience. Additional controls include: asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Standard errors clustered at the participant level in parentheses. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear


*--------------------------------------------------------------------------*
* Main effect by individual/communal decision making (AC update December 2024)
*--------------------------------------------------------------------------*

use "$path/Data/Uganda_WTA_Trees_clean.dta", replace 

foreach v in C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3 consumption female C9 risk D6_9 acresland cutstreescharc {
	
	g miss_`v' = `v'==.
	sum `v', d
	replace `v' = r(p50) if `v'==.
	
}

reshape long share_cut_r trees_cut_r total_trees_r, i(HHID) j(round)
egen distid = group(DISTRICT)
egen hhid = group(HHID)

gen communal_land=.
replace communal_land=1 if E7a==1|E7a==2
replace communal_land=0 if E7a==3|E7a==4

local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3"
local controls_additional "consumption female C9 risk D6_9 acresland cutstreescharc"

label var trees_insecure "Insecure" 
label var trees_certificate "Certificate"

estimates clear

* INDIVIDUAL LAND
*--------------------------------------------------------
* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' if communal_land==0, abs(round miss* enumid) vce(robust) 
sum share_cut if trees_secure==1 & communal_land==0
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' if communal_land==0, abs(round miss* vname) vce(robust) 
sum share_cut if trees_secure==1 & communal_land==0
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'


* COMMUNAL LAND
*--------------------------------------------------------
* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' if communal_land==1, abs(round miss* enumid) vce(robust) 
sum share_cut if trees_secure==1 & communal_land==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local p = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate `controls_ug_unbalanced' `controls_additional' if communal_land==1, abs(round miss* vname)  
sum share_cut if trees_secure==1 & communal_land==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test trees_insecure=trees_certificate
local pshare = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p'

esttab using "$treetablesuganda/trees_main_decisionrights.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" "s3 P-value Insecure=Certificate") keep(trees_insecure trees_certificate) prehead(\begin{tabular}{l*{5}{c}} \hline \hline & \multicolumn{2}{c}{Individual Decision Makers} & \multicolumn{2}{c}{Communal Decision Makers} \\ DV: Share trees cut each round  & (1) & (2) & (3) & (4) \\) posthead(\hline \\) prefoot(\\ Controls: & Y & Y & Y & Y \\ Enumerator FE: & Y & N & Y & N \\ Village FE: & N & Y & N & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. A participant is a communal decision-maker if they indicated that people outside their household have permission to use the land they most frequently use to extract trees or tree products because it is communal land or because it is mailo land. Otherwise they are classified as an individual decision-maker. Controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, patience, mailo land tenure, private land tenure, asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Robust standard errors in parentheses. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear

* Test coefficients across communal and individual *
*--------------------------------------------------------
estimates clear

reg share_cut trees_insecure trees_certificate C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3 consumption female C9 risk D6_9 acresland cutstreescharc i.round miss* i.vid if communal_land==0
estimates store a

reg share_cut trees_insecure trees_certificate C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3 consumption female C9 risk D6_9 acresland cutstreescharc i.round miss* i.vid if communal_land==1
estimates store b 

quietly suest a b, vce(robust) 
test [a_mean]trees_insecure = [b_mean]trees_insecure /* p-val = 0.0638 */
test [a_mean]trees_certificate = [b_mean]trees_certificate /* p-val = 0.1737 */

ttest share_cut if trees_secure==1, by(communal_land) /* p-val = 0.18 */

*--------------------------------------------------------------------------*
* Trust Round and Mailo Round interactions -  (AC update December 2024)
*--------------------------------------------------------------------------*

use "$path/Data/Uganda_WTA_Trees_clean.dta", replace 

foreach v in C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3 consumption female C9 risk D6_9 acresland cutstreescharc {
	
	g miss_`v' = `v'==.
	sum `v', d
	replace `v' = r(p50) if `v'==.
	
}

reshape long share_cut_r trees_cut_r total_trees_r, i(HHID) j(round)
egen distid = group(DISTRICT)
egen hhid = group(HHID)

gen communal_land=.
replace communal_land=1 if E7a==1|E7a==2
replace communal_land=0 if E7a==3|E7a==4

local controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3"
local controls_additional "consumption female C9 risk D6_9 acresland cutstreescharc"

label var trees_insecure "Insecure" 
label var trees_certificate "Certificate"


estimates clear

gen hightrust=trust_sent>2000
bysort vname: egen vmailo = mean(mailo)

* generate round dummies
tabulate round, generate(round_d)


* HIGH TRUST X ROUND
*-------------------------------------------------------
* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' if trees_certificate==0 & trees_insecure==0, abs(miss* enumid) vce(robust) 
eststo: reghdfe share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' if trees_insecure==1, abs(miss* enumid) vce(robust)  
eststo: reghdfe share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' if trees_certificate==1, abs(miss* enumid) vce(robust) 
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
local p = round(r(p),0.01)


* Add controls from the PAP + village fixed effects * 
eststo: reghdfe share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' if trees_certificate==0&trees_insecure==0, abs( miss* vname) vce(robust)
eststo: reghdfe share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' if trees_insecure==1, abs(miss* vname) vce(robust) 
eststo: reghdfe share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' if trees_certificate==1, abs(miss* vname) vce(robust)
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
local p = round(r(p),0.01)


esttab using "$treetablesuganda/trees_interaction_trust_round.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes style(tex)  nobaselevels label coeflabels( 1.hightrust "High Trust" 2.round "Round 2" 3.round  "Round 3"  4.round  "Round 4" 5.round  "Round 5" 6.round  "Round 6" 7.round  "Round 7" 8.round  "Round 8" 9.round  "Round 9" 10.round  "Round 10" 1.hightrust#2.round  "High Trust x Round 2" 1.hightrust#3.round  "High Trust x Round 3" 1.hightrust#4.round  "High Trust x Round 4" 1.hightrust#5.round  "High Trust x Round 5" 1.hightrust#6.round  "High Trust x Round 6" 1.hightrust#7.round  "High Trust x Round 7" 1.hightrust#8.round  "High Trust x Round 8" 1.hightrust#9.round  "High Trust x Round 9" 1.hightrust#10.round  "High Trust x Round 10" ) replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) keep(1.hightrust 2.round 3.round 4.round 5.round 6.round 7.round 8.round 9.round 10.round 1.hightrust#2.round 1.hightrust#3.round 1.hightrust#4.round 1.hightrust#5.round 1.hightrust#6.round 1.hightrust#7.round 1.hightrust#8.round 1.hightrust#9.round 1.hightrust#10.round) prehead(\begin{tabular}{l*{7}{c}} \hline \hline \\ DV: Share trees cut each round  & Secure & Insecure & Certificate & Secure & Insecure & Certificate \\) posthead(\hline \\) prefoot(\\ Controls: & Y & Y & Y & Y & Y & Y \\ Enumerator FE: & Y & Y & Y & N & N & N \\ Village FE: & N & N & N & Y & Y & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. Controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, patience, mailo land tenure, private land tenure, asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Robust standard errors in parentheses. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear


* VILLAGE MAILO X ROUND
*--------------------------------------------------------
* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' if trees_insecure==1, abs(miss* enumid) vce(robust) 
eststo: reghdfe share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' if trees_certificate==1, abs(miss* enumid) vce(robust) 
eststo: reghdfe share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' if trees_certificate==0&trees_insecure==0, abs(miss* enumid) vce(robust) 

local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
local p = round(r(p),0.01)

* Add controls from the PAP + district fixed effects * 
eststo: reghdfe share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' if trees_insecure==1, abs(miss* DISTRICT) vce(robust) 
eststo: reghdfe share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' if trees_certificate==1, abs(miss* DISTRICT) vce(robust)
eststo: reghdfe share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' if trees_certificate==0&trees_insecure==0, abs(miss* DISTRICT) vce(robust)

local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
local p = round(r(p),0.01)


esttab using "$treetablesuganda/trees_interaction_mailo_round.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes style(tex)  nobaselevels label coeflabels( 2.round#c.vmailo  "Village mailo x Round 2" 3.round#c.vmailo  "Village mailo x Round 3" 4.round#c.vmailo  "Village mailo x Round 4" 5.round#c.vmailo  "Village mailo x Round 5" 6.round#c.vmailo  "Village mailo x Round 6" 7.round#c.vmailo  "Village mailo x Round 7" 8.round#c.vmailo  "Village mailo x Round 8" 9.round#c.vmailo  "Village mailo x Round 9" 10.round#c.vmailo  "Village mailo x Round 10" ) replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) keep( 2.round#c.vmailo  2.round#c.vmailo 3.round#c.vmailo 4.round#c.vmailo 5.round#c.vmailo 6.round#c.vmailo 7.round#c.vmailo 8.round#c.vmailo 9.round#c.vmailo 10.round#c.vmailo) prehead(\begin{tabular}{l*{7}{c}} \hline \hline \\ DV: Share trees cut each round  & Secure & Insecure & Certificate & Secure & Insecure & Certificate \\) posthead(\hline \\) prefoot(\\ Controls: & Y & Y & Y & Y & Y & Y \\ Enumerator FE: & Y & Y & Y & N & N & N \\ District FE: & N & N & N & Y & Y & Y \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. Controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, patience, mailo land tenure, private land tenure, asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Robust standard errors in parentheses. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear


* SW looking for convergence by round - HIGH TRUST *
*--------------------------------------------------------------------------*
global controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3"
global controls_additional "consumption female C9 risk D6_9 acresland cutstreescharc"

tabulate round, g(r)
forval i=1(1)10 {
	g trustr`i' = trust*r`i' if round==`i'
	replace trustr`i' = 0 if round~=`i'
}

* Enumerator FE *
*------------------------------------------------
eststo: reghdfe share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' if trees_secure==1, abs(miss* enumid) vce(robust)
eststo: reghdfe share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' if trees_certificate==1, abs(miss* enumid) vce(robust)

* testing coefficients b/w secure and certificate
*------------------------------------------------
reg share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' miss* i.enumid if trees_secure==1 
estimates store a

reg share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' miss* i.enumid if trees_certificate==1 
estimates store b 

quietly suest a b, vce(robust)

test [a_mean]1.hightrust = [b_mean]1.hightrust // Round 1 is different

forval i=1(1)10 {
	test [a_mean]1.hightrust#`i'.round = [b_mean]1.hightrust#`i'.round  // High trust secure v. high trust certificate not different (except for round 7)
}

forval i=2(1)10 {
	test [a_mean]`i'.round = [b_mean]`i'.round // low trust secure v. certificate not different in in rounds 2-10
}

test [a_mean]_cons = [b_mean]_cons // Round 1 different low trust secure v. certificate 



* Village FE *
*------------------------------------------------
eststo: reghdfe share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' if trees_secure==1, abs(miss* vid) vce(robust)
eststo: reghdfe share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' if trees_certificate==1, abs(miss* vid) vce(robust)

* testing coefficients b/w secure and certificate
*------------------------------------------------
reg share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' miss* i.vid if trees_secure==1 
estimates store a

reg share_cut hightrust##i.round `controls_ug_unbalanced' `controls_additional' miss* i.vid if trees_certificate==1 
estimates store b 

quietly suest a b, vce(robust)

test [a_mean]1.hightrust = [b_mean]1.hightrust // Round 1 is not different

forval i=2(1)10 {
	test [a_mean]1.hightrust#`i'.round = [b_mean]1.hightrust#`i'.round  // High trust secure v. high trust certificate not different (except for round 7)
}

forval i=2(1)10 {
	test [a_mean]`i'.round = [b_mean]`i'.round // low trust secure v. certificate not different in rounds 2-10
}
test [a_mean]_cons = [b_mean]_cons // Round 1 different low trust secure v. certificate 




* SW looking for convergence by round - VILLAGE MAILO *
*--------------------------------------------------------------------------*
* Enumerator FE *
*------------------------------------------------
eststo: reghdfe share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' if trees_secure==1, abs(miss* enumid) vce(robust)
eststo: reghdfe share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' if trees_certificate==1, abs(miss* enumid) vce(robust)

* testing coefficients b/w secure and certificate*
*------------------------------------------------
reg share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' miss* i.enumid if trees_secure==1 
estimates store a

reg share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' miss* i.enumid if trees_certificate==1 
estimates store b 

quietly suest a b, vce(robust)
test [a_mean]c.vmailo = [b_mean]c.vmailo // Round 1 is NOT different

forval i=2(1)10 {
	test [a_mean]c.vmailo#`i'.round = [b_mean]c.vmailo#`i'.round  // Subsequent rounds are not different (except for round 10)
}
forval i=2(1)10 {
	test [a_mean]`i'.round = [b_mean]`i'.round // no mailo secure v. certificate not different in rounds 2-10
}
test [a_mean]_cons = [b_mean]_cons // Round 1 different no mailo secure v. certificate 


* District FE *
*------------------------------------------------
eststo: reghdfe share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' if trees_secure==1, abs(miss* DISTRICT) vce(robust)
eststo: reghdfe share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' if trees_certificate==1, abs(miss* DISTRICT) vce(robust)

* testing coefficients b/w secure and certificate*
*------------------------------------------------
egen did = group(DISTRICT)
reg share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' miss* i.did if trees_secure==1 
estimates store a

reg share_cut c.vmailo##i.round `controls_ug_unbalanced' `controls_additional' miss* i.did if trees_certificate==1 
estimates store b 

quietly suest a b, vce(robust)

test [a_mean]c.vmailo = [b_mean]c.vmailo // Round 1 is different (village mailo secure cut more)

forval i=2(1)10 {
	test [a_mean]c.vmailo#`i'.round = [b_mean]c.vmailo#`i'.round  // Subsequent rounds are not different
}
forval i=2(1)10 {
	test [a_mean]`i'.round = [b_mean]`i'.round // no mailo secure v. certificate not different in rounds 2-10 (except round 8)
}
test [a_mean]_cons = [b_mean]_cons // Round 1 NOT different no mailo secure v. certificate 










*--------------------------------------------------------------------------*
* Variation at Cut Off
*--------------------------------------------------------------------------*

use "$path/Data/Uganda_WTA_Trees_clean.dta", replace 

foreach v in C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3 consumption female C9 risk D6_9 acresland cutstreescharc {
	
	g miss_`v' = `v'==.
	sum `v', d
	replace `v' = r(p50) if `v'==.
	
}

reshape long share_cut_r trees_cut_r total_trees_r, i(HHID) j(round)
egen distid = group(DISTRICT)
egen hhid = group(HHID)


global controls_ug_unbalanced "C8_1_TEXT C1 D6_2 D6_7 patience mailo private E8_3"
global controls_additional "consumption female C9 risk D6_9 acresland cutstreescharc"

label var trees_insecure "Insecure" 
label var trees_certificate "Certificate"

estimates clear


*gen justbelow5=.
*replace justbelow5 = 1 if inlist(mod(total_trees, 5), 3, 4)
*replace justbelow5 = 0 if inlist(mod(total_trees, 5), 0, 1)
*replace justbelow5 = . if total_trees==0|total_trees==1

*** modifying this slightly
gen justbelow5 = inlist(mod(total_trees, 5),4)
gen justabove5 = inlist(mod(total_trees,5),1)
replace justabove5=0 if total_trees==1 // no regrowth possible here (SW)



* Distance to threshold (SW) *
*--------------------------------------------------------
g distthresh = mod(total_trees, 5)
replace distt=-1 if distt==3
replace distt=-2 if distt==4

twoway (lpolyci share_cut distthresh if trees_secure==1) (lpolyci share_cut distt if trees_insecure==1) (lpolyci share_cut distt if trees_certificate==1), ytitle("Share Cut") xtitle("Distance to Threshold") legend(order(1 "95% CI" 2 "Secure" 3 "Insecure" 4 "Certificate")) scheme(s2mono)

g below2 = distt==-2
g below1 = distt==-1
g above1 = distt==1
g above2 = distt==2

label var below2 "2 Below"
label var below1 "1 Below"
label var above2 "2 Above"
label var above1 "1 Above"

eststo: reghdfe share_cut trees_insecure trees_certificate below2 below1 above1 above2  `controls_ug_unbalanced' `controls_additional', abs(round miss* enumid) vce(robust)
sum share_cut 
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test below2 = below1 = above2
local p1 = round(r(p),0.01)
test below2 = below1 = above2 = above1
local p2 = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p1'
estadd scalar s4 `p2'

eststo: reghdfe share_cut below2 below1 above1 above2  `controls_ug_unbalanced' `controls_additional' if trees_secure==1, abs(round miss* enumid) vce(robust)
sum share_cut if trees_secure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test below2 = below1 = above2
local p1 = round(r(p),0.01)
test below2 = below1 = above2 = above1
local p2 = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p1'
estadd scalar s4 `p2'

eststo: reghdfe share_cut below2 below1 above1 above2  `controls_ug_unbalanced' `controls_additional' if trees_insecure==1, abs(round miss* enumid) vce(robust)
sum share_cut if trees_insecure==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test below2 = below1 = above2
local p1 = round(r(p),0.01)
test below2 = below1 = above2 = above1
local p2 = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p1'
estadd scalar s4 `p2'

eststo: reghdfe share_cut below2 below1 above1 above2  `controls_ug_unbalanced' `controls_additional' if trees_certificate==1, abs(round miss* enumid) vce(robust)
sum share_cut if trees_certificate==1
local ymean = round(r(mean),0.01)
local ysd = round(r(sd),0.01)
test below2 = below1 = above2
local p1 = round(r(p),0.01)
test below2 = below1 = above2 = above1
local p2 = round(r(p),0.01)
estadd scalar s1 `ymean'
estadd scalar s2 `ysd'
estadd scalar s3 `p1'
estadd scalar s4 `p2'


esttab using "$treetablesuganda/trees_discontinuity.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("s1 Mean Secure Group" "s2 SD Secure Group" "s3 P-value 2 Below=1 Below=2 Above" "s4 P-value 2 Below=1 Below=2 Above") keep(trees_insecure trees_certificate below2 below1 above1 above2) prehead(\begin{tabular}{l*{5}{c}} \hline \hline & Full Sample & Secure & Insecure & Certificate} \\ DV: Share trees cut each round  & (1) & (2) & (3) & (4) \\) posthead(\hline \\) prefoot(\\ Controls: & Y & Y & Y & Y \\ Enumerator FE: & Y & Y & Y & Y \\ Village FE: & N & N & N & N \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a person-round. All estimates control for round fixed effects. Controls include: age, household size, whether the respondent could obtain money from village/community savings if in need, whether the respondent could obtain money from selling trees or charcoal if in need, whether land owned is used for people to live on, patience, mailo land tenure, private land tenure, asset index, sex, education, risk tolerance, land area, and whether or not respondent/household sells trees for or produces charcoal. Robust standard errors in parentheses. Missing observations for control variables replaced with the median value. All estimates control for missing observations.} \end{tablenotes} )
estimates clear


* AC Regressions 
*--------------------------------------------------------

* Share Cut *
reghdfe share_cut trees_insecure trees_certificate justbelow5 justabove5  `controls_ug_unbalanced' `controls_additional', abs(round miss* enumid) vce(robust)

reghdfe share_cut justbelow5 justabove5  `controls_ug_unbalanced' `controls_additional' if trees_insecure == 1, abs(round miss* enumid) vce(robust)
reghdfe share_cut justbelow5 justabove5  `controls_ug_unbalanced' `controls_additional' if trees_certificate  == 1, abs(round miss* enumid) vce(robust)
reghdfe share_cut  justbelow5  justabove5 `controls_ug_unbalanced' `controls_additional' if trees_insecure==0 & trees_certificate==0, abs(round miss* enumid) vce(robust) 


* SW: Testing coefficients *
reg share_cut justbelow5 justabove5  `controls_ug_unbalanced' `controls_additional' i.round i.enumid miss* if trees_insecure == 1
estimates store a

reg share_cut justbelow5 justabove5  `controls_ug_unbalanced' `controls_additional' i.round i.enumid miss* if trees_certificate  == 1 
estimates store b

reg share_cut  justbelow5  justabove5 `controls_ug_unbalanced' `controls_additional' i.round i.enumid miss* if trees_insecure==0 & trees_certificate==0
estimates store c

quietly suest a b c, vce(robust)
test [a_mean]justbelow5 = [b_mean]justbelow5  
test [b_mean]justbelow5 = [c_mean]justbelow5  
test [a_mean]justbelow5 = [c_mean]justbelow5

test [a_mean]justabove5 = [b_mean]justabove5  
test [b_mean]justabove5 = [c_mean]justabove5  
test [a_mean]justabove5 = [c_mean]justabove5  



* INDIVIDUAL LAND
*--------------------------------------------------------
* Add controls from the PAP + enumerator fixed effects * 
eststo: reghdfe share_cut trees_insecure trees_certificate   `controls_ug_unbalanced' `controls_additional', abs(round miss* enumid) vce(robust) 
eststo: reghdfe share_cut trees_insecure trees_certificate justbelow5  `controls_ug_unbalanced' `controls_additional', abs(round miss* enumid)  
eststo: reghdfe share_cut  justbelow5  `controls_ug_unbalanced' `controls_additional' if trees_insecure==1, abs(round miss* enumid) vce(robust) 
eststo: reghdfe share_cut  justbelow5  `controls_ug_unbalanced' `controls_additional' if trees_certificate==1, abs(round miss* enumid) vce(robust) 
eststo: reghdfe share_cut  justbelow5  `controls_ug_unbalanced' `controls_additional' if trees_insecure==0 & trees_certificate==0, abs(round miss* enumid) vce(robust) 



*--------------------------------------------------------------------------*
* Cost of Certificates and Observables -  (AC update December 2024)
*--------------------------------------------------------------------------*
estimates clear
*** Generate variable identifying round certificate bought
use "$path/Data/Uganda_WTA_Trees_clean.dta", replace // SW using cross-sectional data

gen certificate_round=.
replace certificate_round=2 if cert_r2==1
replace certificate_round=3 if cert_r2==0&cert_r3==1
replace certificate_round=4 if cert_r3==0&cert_r4==1
replace certificate_round=5 if cert_r4==0&cert_r5==1
replace certificate_round=6 if cert_r5==0&cert_r6==1
replace certificate_round=7 if cert_r6==0&cert_r7==1
replace certificate_round=8 if cert_r7==0&cert_r8==1
replace certificate_round=9 if cert_r8==0&cert_r9==1
replace certificate_round=10 if cert_r9==0&cert_r10==1

g certround2 = certificate_round==2
replace certround2=. if certbuy==0 | certbuy==.

label var female "Female"
label var certbuy "Bought certificate"

estimates clear


file open myfile using  "$treetablesuganda/trees_cert_cost_observables.tex", write replace
file write myfile "\begin{tabular}{lcccc} \hline \hline "
file write myfile "&  \multicolumn{2}{c}{Bought Certificate} & \multicolumn{2}{c}{Tree Payout}\\ "
file write myfile "&  \multicolumn{2}{c}{in Round 2}  & \multicolumn{2}{c}{Total (UGX)}\\ "
file write myfile " Variable &  (1) & (2)  &  (1) & (2)  \\ \hline "

foreach v in certbuy female C1 C3 primaryschool secondaryschool C12_1_TEXT income_land acresland D1_1_TEXT E4_1_TEXT treecoverage cutstreescharc E8_1 E8_2 E8_3 B12a_1_TEXT consumption D6_1 D6_2  D6_3  D6_4  D6_5  D6_7  D7_7  risk patience  {
	
	
	reghdfe certround2 `v' if trees_certificate==1, a(enumid) vce(robust) keepsing
	matrix A = r(table)
	local pval1 = A[4,1]
	local coef=round(_b[`v'], 0.001)
	if `pval1'>0.1  {
	local coef1 = string(`coef',"%8.3f") 
 } 
 else if `pval1'>0.05 { 
	local coef1 = string(`coef',"%8.3f")  + "$^\star$"
 }
  else if `pval1'>0.01 { 
	local coef1 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$"
 }
 else {
 	local coef1 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$" + "$^\star$"
 }
 
 
	reghdfe certround2 `v' if trees_certificate==1, a(vname) vce(robust) keepsing
	matrix A = r(table)
	local pval1 = A[4,1]
	local coef=round(_b[`v'], 0.001)
	if `pval1'>0.1  {
	local coef2 = string(`coef',"%8.3f") 
 } 
 else if `pval1'>0.05 { 
	local coef2 = string(`coef',"%8.3f")  + "$^\star$"
 }
  else if `pval1'>0.01 { 
	local coef2 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$"
 }
 else {
 	local coef2 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$" + "$^\star$"
 }
 
 	
	reghdfe tree_payout `v' if trees_certificate==1, a(enumid) vce(robust) keepsing 
	matrix A = r(table)
	local pval1 = A[4,1]
	local coef=round(_b[`v'], .001)
	if `pval1'>0.1  {
	local coef5 = string(`coef',"%8.3f") 
 } 
 else if `pval1'>0.05 { 
	local coef5 = string(`coef',"%8.3f")  + "$^\star$"
 }
  else if `pval1'>0.01 { 
	local coef5 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$"
 }
 else {
 	local coef5 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$" + "$^\star$"
 }
	
	reghdfe tree_payout `v' if trees_certificate==1, a(vname) vce(robust) keepsing
	matrix A = r(table)
	local pval1 = A[4,1]
	local coef=round(_b[`v'], .001)
	if `pval1'>0.1  {
	local coef6 = string(`coef',"%8.3f") 
 } 
 else if `pval1'>0.05 { 
	local coef6 = string(`coef',"%8.3f")  + "$^\star$"
 }
  else if `pval1'>0.01 { 
	local coef6 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$"
 }
 else {
 	local coef6 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$" + "$^\star$"
 }
 
 
 
	local lbl: variable label `v'
	file write myfile "`lbl'  & `coef1' & `coef2' & `coef5'  & `coef6'  \\"
}


foreach v in mailo customary private  {
	
	bysort vid: egen v`v' = mean(`v')
	label var v`v' "Village share `v'"
	
	reghdfe certround2 v`v' if trees_certificate==1, a(enumid) vce(robust) keepsing
	matrix A = r(table)
	local pval1 = A[4,1]
	local coef=round(_b[v`v'], 0.001)
	if `pval1'>0.1  {
	local coef1 = string(`coef',"%8.3f") 
 } 
 else if `pval1'>0.05 { 
	local coef1 = string(`coef',"%8.3f")  + "$^\star$"
 }
  else if `pval1'>0.01 { 
	local coef1 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$"
 }
 else {
 	local coef1 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$" + "$^\star$"
 }
 
 
	reghdfe certround2 v`v' if trees_certificate==1, a(DISTRICT) vce(robust) keepsing
	matrix A = r(table)
	local pval1 = A[4,1]
	local coef=round(_b[v`v'], 0.001)
	if `pval1'>0.1  {
	local coef2 = string(`coef',"%8.3f") 
 } 
 else if `pval1'>0.05 { 
	local coef2 = string(`coef',"%8.3f")  + "$^\star$"
 }
  else if `pval1'>0.01 { 
	local coef2 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$"
 }
 else {
 	local coef2 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$" + "$^\star$"
 }
 
 	
	reghdfe tree_payout v`v' if trees_certificate==1, a(enumid) vce(robust) keepsing 
	matrix A = r(table)
	local pval1 = A[4,1]
	local coef=round(_b[v`v'], .001)
	if `pval1'>0.1  {
	local coef5 = string(`coef',"%8.3f") 
 } 
 else if `pval1'>0.05 { 
	local coef5 = string(`coef',"%8.3f")  + "$^\star$"
 }
  else if `pval1'>0.01 { 
	local coef5 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$"
 }
 else {
 	local coef5 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$" + "$^\star$"
 }
	
	reghdfe tree_payout v`v' if trees_certificate==1, a(DISTRICT) vce(robust) keepsing
	matrix A = r(table)
	local pval1 = A[4,1]
	local coef=round(_b[v`v'], .001)
	if `pval1'>0.1  {
	local coef6 = string(`coef',"%8.3f") 
 } 
 else if `pval1'>0.05 { 
	local coef6 = string(`coef',"%8.3f")  + "$^\star$"
 }
  else if `pval1'>0.01 { 
	local coef6 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$"
 }
 else {
 	local coef6 = string(`coef',"%8.3f")  + "$^\star$" + "$^\star$" + "$^\star$"
 }
 
 
 
	local lbl: variable label v`v'
	file write myfile "`lbl'  & `coef1' & `coef2' & `coef5'  & `coef6'  \\"
}


file write myfile "\hline Mean DV: & 0.88 & 0.88 & 11982 & 11982 \\ SD DV: & 0.32 & 0.32 & 3419 & 3419 \\  Enumerator FE: & Y & N  & Y & N  \\ Village FE: & N & Y & N & Y \\ \hline \hline"
file write myfile " \end{tabular} " _n
file write myfile "\begin{tablenotes} \item \scriptsize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. OLS estimates. Unit of observation is a participant in the certificate treatment group (N=509). The first two columns are restricted to participants who purchased a certificate (N=408). Each coefficient is the outcome of regressing the round in which a certificate was bought (first two columns) and the total earnings from the tree experiment (second two columns) on the variable indicated, controlling for enumerator fixed effects in column (1) and village fixed effects in column (2), except for the last three rows (Village share of mailo, customary and private tenure), which use district fixed effects. All estimates use robust standard errors.} \end{tablenotes}"
file close myfile

